package com.sline.TCP;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Demo1_Server {
    public static void main(String[] args) throws IOException {
        ServerSocket server = new ServerSocket(12345);
        Socket socket = server.accept();
        InputStream is = socket.getInputStream();
        OutputStream os = socket.getOutputStream();

        while (true) {
            byte[] arr = new byte[1024];
            int len = is.read(arr);
            String msg = new String(arr, 0, len);

            System.out.println("服务器收到请求内容: " + msg);

            os.write("百度一下, 你就知道".getBytes());
        }
    }
}
